<template>
  <div class="home">
    <div class="box">
      <div class="box-info tc">
        ——Enemy——
      </div>
      <div class="box-info">名称：敌人</div>
      <div class="box-info">HP: 20/20 </div>
      <div class="box-info">LV: 1</div>
    </div>
    <div class="box">
      <div class="box-info tc">
        ——Player——
      </div>
      <div class="box-info">HP: 20/20</div>
      <div class="box-info">LV: 1</div>
    </div>
    <div class="action-box">
      <div class="box-info box-title">
        ——Action——
      </div>
      <div class="box-info">攻击</div>
      <div class="box-info"  @click="open(`skill`)">技能</div>
      <div class="box-info"  @click="open(`goods`)">物品</div>
      <div class="box-info">逃跑</div>
    </div>
    <div class="box">
      <div class="box-info">
        战斗开始
      </div>
    </div>

    <Popup :show.sync="show" :title="curListType == `skill` ? `技能` : `物品`">
      <div>
        <ul class="list">
          <li class="item" v-for="(item, index) in list" :key="index">{{item.name}}/{{curListType == `skill` ? `mp` : `剩余`}}：{{item.consume}}</li>
        </ul>
      </div>
    </Popup>
  </div>
</template>

<script>
import Popup from "@/components/base/popup";
export default {
  components: { Popup },
  data() {
    return {
      curListType: ``,
      show: false,
      isEnd: false,
      player: {},
      enemy: {},
      log: [] // 战斗日志
    };
  },
  computed: {
    list() {
      return this.curListType === `skill`
        ? [
            {
              name: "强力击",
              consume: 5
            }
          ]
        : [
            {
              name: "生命药水",
              consume: 5
            }
          ];
    }
  },
  watch: {
    isEnd(nv) {
      if (nv) {
        // 结束战斗
        console.log(`this battle is over`);
      }
    }
  },
  methods: {
    open(type) {
      console.log(this.show);
      this.show = true;
      this.curListType = type;
    },
    // 处理技能效果
    handleSkill(skills) {
      skills.forEach(act => {
        let target = this.getTarget(act.target);
        target[act.attr] += act.value;
      });
    },
    // 处理正常操作，攻击，技能，物品，逃跑
    handleAction(type) {
      switch (type) {
        case `ATTCK`:
          // 普通攻击
          break;
        case `SKILL`:
          // 打开技能列表
          break;
        case `GOODS`:
          // 打开物品列表
          break;
        case `ESCAPE`:
          this.handleEscape();
          break;
      }
    },
    handleEscape() {
      this.isEnd = true;
    },
    getTarget(target) {
      return target === "SELF" ? this.player : this.enemy;
    }
  }
};
</script>
<style scoped>
.item {
  list-style: none;
}
.box {
  border: 1px solid #e7e7e7;
  padding: 10px;
  margin-bottom: 15px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
}
.action-box {
  border: 1px solid #e7e7e7;
  padding: 10px;
  margin-bottom: 15px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.action-box .box-info {
  width: 50%;
  text-align: center;
}
.action-box .box-title {
  width: 100%;
}
.box-info {
  width: 100%;
  line-height: 32px;
  text-align: left;
}
.tc {
  text-align: center;
}
</style>
